%%%HEADER%%%

OpenFeint Android Quick Start Guide


<<Prev Next >>
 

Build and run the OpenFeint Sample Application

The sample app lets you experiment with the features you've configured on the OpenFeint dev dashboard before you've begun to write your own app. Once you do begin working with your own app, it is frequently helpful to come back to the sample app to see how individual features work and how they can best be implemented.
  • Build and run the OpenFeint Sample App for Android in Eclipse

    NOTE: The following instructions assume you are using a standard installation of the Android SDK with the Eclipse IDE as described at http://developer.android.com/sdk/index.html. Adjustments may be required if your development environment is set up differently. The "Hello World" sample app tutorial at http://developer.android.com/sdk/index.html is recommended as a good way to test that your development environment is set up properly.

    1. Save the Contents of the OpenFeint Android SDK package in a convenient location. Everything you need from this package to build the sample app is in the directory called MyOpenFeintSample. You may copy this directory out of the package and rename it if you want to use it as a starting point for experimental code.
    2. To develop in Eclipse:
      1. Open Eclipse with an empty workspace. This will present an empty "Project Explorer" pane to which you will add a reference to the sample app project.
      2. Make sure that the path to your Android SDK has been set for this workspace. To set it:
        • On a Mac, go to: Eclipse-->Preferences-->Android-->SDK Location.
        • On Windows, go to: Window-->Preferences-->Android-->SDK Location.
      3. Add the sample app project to the workspace:
        • Right click in the empty Project Explorer pane and select Import.
        • Select General -->Existing Projects into Workspace from the import dialog.
        • Click the Next button.
        • Click Select root directory. Click Browse. Navigate to the MyOpenFeintSample directory in the OpenFeint package.
        • Click Open.
        • Click the Finish button.
        • The MyOpenFeintSample is now listed in the project window.
          Clicking the triangle next to MyOpenFeintSample should reveal an outline like this:
          Project OK
      4. Add your product information to the sample app:
        1. Bring up the OpenFeint developer dashboard ( https://api.openfeint.com/dd) in a browser. Choose the game you will use with the sample application. Click the Application Information button to show the properties of the application you defined:
          App Properties
        2. In Eclipse, edit MyOpenFeintSample/src/com.openfeint.example/OpenFeintApplication.java; construct your OpenFeint settings object using the game name, game ID, game key, and game secret of your game as defined on the OpenFeint developer site:
          1. The values can be set in the class definition of the source code of your main Application:
            static final String gameName = "Name of your application";
            static final String gameID = "gameID";
            static final String gameKey = "gameKey";
            static final String gameSecret = "gameSecret";
            
            For example, in the sample application, you could add these lines in src/com.openfeint.example/OpenFeintApplication.java after:
             public class OpenFeintApplication extends Application {
          2. Use the variables you defined to construct your settings object. This can be done in the onCreate() method of your Application object:
            OpenFeintSettings settings = new OpenFeintSettings(
                 gameName, gameKey, gameSecret, gameID);
            For example, in the sample application, replace this line:
            OpenFeintSettings settings =
                new OpenFeintSettings(
                   "App Name", "App Key", "App Secret", "App ID", options);
            in the onCreate() method in src/com.openfeint.example/OpenFeintApplication.java with this line:
            OpenFeintSettings settings = new OpenFeintSettings(
                 gameName, gameKey, gameSecret, gameID);
      5. Add the OpenFeint SDK project to the workspace:
        • Right click in the empty space in the Project Explorer pane and select Import.
        • Select General -->Existing Projects into Workspace from the import dialog.
        • Click the Next button.
        • Click Select root directory. Click Browse. Navigate to the sdk directory in the OpenFeint package.
        • Click Open.
        • Click the Finish button.
        • The OpenFeintAPI is now listed in the project window.
          Clicking the triangle next to MyOpenFeintSample should reveal an outline like this:
          SDK OK
      6. If you see a warning that reads, Android requires .class compatibility set to 5.0. Please fix project properties...:
        1. Right-click on the project name.
        2. Android Tools->Fix Project Properties
        3. Exit and then restart Eclipse.
      7. Try building the project to confirm that there are no build errors.
        • If Project -->Build Automatically is checked, the project will try to rebuild itself whenever its binaries are not up to date with its sources and will likely be ready to run or debug on a connected device.
        • If Project -->Build Automatically is not checked, you can manually request a build with Project--> Build Project.
        • If there are build errors, a mark appears over the project icon the list of errors appears in the Markers pane:
          Project Error
        • If you see an error that reads something like Project 'MyOpenFeintSample' is missing required source folder: 'gen'" or if Eclipse cannot create R.java, add the gen/ directory to the Project.
        • If you see a similar error for the OpenFeintAPI project, add the gen/ directory to the Project.
          Note: Visit this list for solutions to some common build errors.
      8. Some things to try if your project does not build :
        • Make sure the Android target is version 2.1 or greater:
          • Right-click each project and select Properties.
          • Click Android and select a target that is version 2.1 or greater.
        • Important: Make sure the Java Compiler Compliance Level is set correctly:
          • Right-click each project and click Properties.
          • Click Java Compiler and set the Compiler Compliance Level to 1.6.
        • If you get an error about having to fix Android Properties:
          • Right-click each project, select Android Tools and then select Fix Project Properties.
          • If it appears that nothing happened, click File->Restart in the Eclipse top menu. When Eclipse restarts, it should all be working.
        • Don't worry about warnings that the minSdkVersion is lower than the target API.
      9. Depending on your version of Eclipse and the Android tools, you may need to close the MyOpenFeintSample project and re-open it for it to correctly link to the OpenFeintAPI Android Library. The usual symptom for this is a java.lang.NoClassDefFoundError when trying to launch the sample application. If you experience this, right-click on the MyOpenFeintSample folder, select 'Close Project', then right-click on it again and select 'Open Project'. After rebuilding, the crash should be gone.
      10. Run the sample application on an Android device or simulator.
        • You may use a USB cable to attach an Anrdoid device if configured for remote debugging or allow the Android simulator to be used if no device is attached.
        • Click the Run button or select Run from the Run menu.
        • If the Run As dialog appears, select Android Application and click OK.
          Run As

          If successful, the sample app displays a list of OpenFeint features that you can test.
  • Build and run the OpenFeint Sample App for Android in Ant
    1. Register an application using the OpenFeint developer dashboard at https://api.openfeint.com/dd. There are step by step instructions here.
    2. Download the latest version of the OpenFeint SDK for Android.
    3. Extract the package.
    4. Run android.bat update lib-project –p /sdk/
    5. Add the line android.library.reference.1=FullPathToOpenFeintPackage/sdk/ to the build.properties file of the game.
    6. Create a directory in which to build your sample application.
    7. Copy the entire MyOpenFeintSample directory from the SDK download (It should be in the download/OpenFeint.%%%VERSION%%% folder) into the new directory you created.
    8. Open the MyOpenFeintSample/src/com/openfeint/example/OpenFeintApplication.java file and provide your game's name, key, secret, and id to OpenFeintSettings. You can find these in the developer dashboard at https://api.openfeint.com/dd.
    9. Copy the entire OpenFeintAPI directory from the download/OpenFeint.%%%VERSION%%% folder into the root of the new directory.
    10. In a command window, change directories to the directory into which you placed the MyOpenFeintSample and the OpenFeintAPI.
    11. In the same command window, run:
      android update lib-project -p OpenFeintAPI/
      The following message appears:
      Updated local.properties
      Added file OpenFeintAPI/proguard.cfg
      						
    12. Change your working directory to the location into which you copied the OpenFeint sample application:
      cd dirContainingMyOpenFeintSample/MyOpenFeintSample
      						
    13. In the same command window, run:
      android update project -p
      The following message appears:
      Updated local.properties
      Added file ././proguard.cfg
      						
    14. Now enter:
      ant debug